#!/usr/bin/python3
import sys

try:
    t = int(input())
    if t < 1 or t > 20:
        sys.exit(0)
    for t1 in range(t):
        n = int(input())
        rc = 5 + 4 * n
        square = [['.'] * rc for i in range(rc)]
        for j in range(rc // 2 - 2, rc // 2 + 3):
            square[rc // 2][j] = square[j][rc // 2] = '$'
        for j in range(1, n + 1):
            x = j * 2
            y = 2 * j - 1
            square[x][y] = square[x][y + 1] = square[x - 1][y + 1] = '$'
            y = rc - j * 2 - 1
            square[x][y] = square[x][y + 1] = square[x - 1][y] = '$'
            x = rc - j * 2 - 1
            square[x][y] = square[x][y + 1] = square[x + 1][y] = '$'
            y = 2 * j - 1
            square[x][y] = square[x][y + 1] = square[x + 1][y + 1] = '$'
            for jj in range(j * 2, rc - j * 2):
                square[jj][(j - 1) * 2] = square[(j - 1) * 2][jj] = square[rc - (j - 1) * 2 - 1][jj] = square[jj][
                    rc - (j - 1) * 2 - 1] = '$'
        print("Case #%s:" % (t1 + 1))
        for i in range(rc):
            print("".join(square[i]))
except ValueError:
    pass
except EOFError:
    pass
except MemoryError:
    pass
